﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCMS.Model;

namespace SCMS.CoreBusinessLogic.NotificationsManager
{
    public class NotificationHelper
    {
        #region .Activity Codes/Document Codes.

        public const string orCode = "OR";
        public const string taCode = "TA";
        public const string poCode = "PO";
        public const string rfpCode = "RFP";
        public const string rfaCode = "RFA";
        public const string wrnCode = "WRN";
        public const string spmCode = "SPM";
        public const string ecfCode = "ECF";
        public const string grnCode = "GRN";
        public const string wbCode = "WB";
        public const string tafCode = "TAF";
        public const string ccCode = "CC";
        public const string paramsCode = "PARAMS";
        public const string ppCode = "PP";

        #endregion

        #region .Action Types.

        public const string approvalCode = "Approval";
        public const string authorizationCode = "Authorization";
        public const string reviewCode = "Finance Review";
        public const string postFundsCode = "Fund Posting";
        public const string verificationCode = "Verification";

        #endregion

        #region .Message Bodies.

        public const string wbMsgBody = "Dear Sir/Madam \nThe issued Way Bill Ref No. {0} has been received with incorrect quantities and/or damaged on the following items.\n{1}. \nThank You";
        public const string ppMsgBody = "Dear {0} \nProcurement Plan Ref No. {1} has some new items which have been added to it. Please log into your system account to approve them.\n \nThank You";

        public const string orMsgBody = "Dear {0}, \nYou have an Order Request waiting for your approval. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string taMsgBody = "Dear {0}, \nYou have a Tender Analysis waiting for your evaluation. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string poMsgBody = "Dear {0}, \nYou have a Purchase Order waiting for your financial review. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string rfpMsgBody = "Dear {0}, \nYou have a Request For Payment waiting for your financial review. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string rfaMsgBody = "Dear {0}, \nYou have a Request For Advance waiting for your financial review. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string wrnMsgBody = "Dear {0}, \nYou have a Warehouse Release Order waiting for your approval. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string spmMsgBody = "Dear {0}, \nYou have a Salary Payment request waiting for your financial review. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string ecfMsgBody = "Dear {0}, \nYou have an Expense Claim request waiting for your financial review. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string grnMsgBody = "Dear {0}, \nYou have an Goods Received Note waiting for your verification. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string tafMsgBody = "Dear {0}, \nYou have a Travel Authorisation Form waiting for your approval. \nPlease login to your system account and take appropriate action. \nThanks";

        public const string orMsgReviewBody = "Dear {0}, \nOrder Request Ref No. {1} has been approved and is waiting for your financial review. \nPlease log in into your system account for details. \nThank You";

        public const string orAuthMsgBody = "Dear {0}, \nOrder Request Ref No. {1} has been approved and financially reviewed and is waiting for your authorization. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string taAuthMsgBody = "Dear {0}, \nTender Analysis Ref No. {1} has been evaluated and is waiting for your authorization. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string poAuthMsgBody = "Dear {0}, \nPurchase Order Ref No. {1} has been approved and is waiting for your authorization. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string rfpAuthMsgBody = "Dear {0}, \nRequest For Payment Ref No. {1} has been approved and is waiting for your authorization. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string rfaAuthMsgBody = "Dear {0}, \nRequest For Advance Ref No. {1} has been approved and is waiting for your authorization. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string wrnAuthMsgBody = "Dear {0}, \nWarehouse Release Note Ref No. {1} has been approved and is waiting for your authorization. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string spmAuthMsgBody = "Dear {0}, \nSalary Payment request Ref No. {1} has been approved and is waiting for your authorization. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string ecfAuthMsgBody = "Dear {0}, \nExpense Claim request request Ref No. {1} has been approved and is waiting for your authorization. \nPlease login to your system account and take appropriate action. \nThank You";
        public const string grnRegAssetsMsgBody = "Dear {0}, \nGoods Received Note Ref No. {1} has been approved. \nPlease login to your system account and proceed with Asset Registration. \nThank You";
        public const string tafAuthMsgBody = "Dear {0}, \nTravel Authorisation Form Ref No. {1} has been approved and is waiting for your authorization. \nPlease login to your system account and take appropriate action. \nThanks";

        public const string orApprovedMsgBody = "Dear {0}, \nOrder Request Ref No. {1} has been approved and forwarded for review. \nThank You";
        public const string taEvaluatedMsgBody = "Dear {0}, \nTender Analysis Ref No. {1} has been evaluated and forwarded for authorization. \nThank You";
        public const string poApprovedMsgBody = "Dear {0}, \nPurchase Order Ref No. {1} has been approved and forwarded for authorization. \nThank You";
        public const string rfpApprovedMsgBody = "Dear {0}, \nRequest For Payment Ref No. {1} has been approved and forwarded for authorization. \nThank You";
        public const string rfaApprovedMsgBody = "Dear {0}, \nRequest For Advance Ref No. {1} has been approved and forwarded for authorization. \nThank You";
        public const string wrnApprovedMsgBody = "Dear {0}, \nWarehouse Release Order Ref No. {1} has been approved. Please proceed with the necessary steps. \nThank You";
        public const string spmApprovedMsgBody = "Dear {0}, \nSalary Payment request Ref No. {1} has been approved and forwarded for authorization. \nThank You";
        public const string tafApprovedMsgBody = "Dear {0}, \nTravel Authorization Ref No. {1} has been approved and forwarded for authorization. \nThank You";
        public const string ecfApprovedMsgBody = "Dear {0}, \nExpense Claim request request Ref No. {1} has been approved and forwarded for authorization. \nThank You";
        public const string grnApprovedMsgBody = "Dear {0}, \nGoods Received Note Ref No. {1} has been verified. \nThank You";

        public const string orMsgReviewedBody = "Dear {0}, \nOrder Request Ref No. {1} has been financially reviewed and forwarded for authorization. \nThank You";

        public const string orAuthorizedMsgBody = "Dear {0}, \nOrder Request Ref No. {1} has been authorized. \nPlease proceed with the necessary steps. \nThank You";
        public const string taAuthorizedMsgBody = "Dear {0}, \nTender Analysis Ref No. {1} has been authorized. \nPlease proceed with the necessary steps. \nThank You";
        public const string poAuthorizedMsgBody = "Dear {0}, \nPurchase Order Ref No. {1} has been authorized. \nPlease proceed with the necessary steps. \nThank You";
        public const string rfpAuthorizedMsgBody = "Dear {0}, \nRequest For Payment Ref No. {1} has been authorized. \nPlease proceed with the necessary steps. \nThank You";
        public const string rfpMsgBodyForPosting = "Dear {0}, \nRequest For Payment Ref No. {1} has been authorized. \nPlease proceed and post the funds in the system. \nThank You";
        public const string rfaAuthorizedMsgBody = "Dear {0}, \nRequest For Advance Ref No. {1} has been authorized. \nPlease proceed with the necessary steps. \nThank You";
        public const string rfaMsgBodyForPosting = "Dear {0}, \nRequest For Advance Ref No. {1} has been authorized. \nPlease proceed and post the funds in the system. \nThank You";
        public const string spmAuthorizedMsgBody = "Dear {0}, \nSalary Payment request Ref No. {1} has been authorized. \nPlease proceed with the necessary steps. \nThank You";
        public const string spmMsgBodyForPosting = "Dear {0}, \nSalary Payment request Ref No. {1} has been authorized. \nPlease proceed and post the funds in the system. \nThank You";
        public const string ecfAuthorizedMsgBody = "Dear {0}, \nExpense Claim request request Ref No. {1} has been authorized. \nPlease proceed with the necessary steps. \nThank You";
        public const string ecfMsgBodyForPosting = "Dear {0}, \nExpense Claim request request Ref No. {1} has been authorized. \nPlease proceed and settle the payment in the system. \nThank You";
        public const string tafAuthorizedMsgBody = "Dear {0}, \nTravel Authorisation Form Ref No. {1} has been authorized. \nPlease proceed with the necessary steps. \nThanks";

        public const string rfpFundsPostedMsgBody = "Dear {0}, \nFunds for Request For Payment Ref No. {1} have been posted. \nThank you for using SCMS";
        public const string rfaFundsPostedMsgBody = "Dear {0}, \nFunds for Request For Advance Ref No. {1}  have been posted. \nThank you for using SCMS";
        public const string spmFundsPostedMsgBody = "Dear {0}, \nFunds for Salary Payment request Ref No. {1} have been posted. \nThank you for using SCMS";
        public const string tafFundsPostedMsgBody = "Dear {0}, \nFunds for Travel Authorization Form Ref No. {1} have been posted. \nThank you for using SCMS";
        public const string ecfFundsPostedMsgBody = "Dear {0}, \nFunds for Expense Claim request request Ref No. {1} have been posted. \nThank you for using SCMS";

        public const string orRejectedMsgBody = "Dear {0}, \nOrder Request Ref No. {1} has been rejected. \nBelow are the remarks: \n\n{2}";
        public const string taRejectedMsgBody = "Dear {0}, \nTender Analysis Ref No. {1} has been rejected. \nBelow are the remarks: \n\n{2}";
        public const string poRejectedMsgBody = "Dear {0}, \nPurchase Order Ref No. {1} has been rejected. \nBelow are the remarks: \n\n{2}";
        public const string rfpRejectedMsgBody = "Dear {0}, \nRequest For Payment Ref No. {1} has been rejected. \nBelow are the remarks: \n\n{2}";
        public const string rfaRejectedMsgBody = "Dear {0}, \nRequest For Advance Ref No. {1} has been rejected. \nBelow are the remarks: \n\n{2}";
        public const string wroRejectedMsgBody = "Dear {0}, \nWarehouse Release Order request Ref No. {1} has been rejected. \nBelow are the remarks: \n\n{2}";
        public const string spmRejectedMsgBody = "Dear {0}, \nSalary Payment request Ref No. {1} has been rejected. \nBelow are the remarks: \n\n{2}";
        public const string tafRejectedMsgBody = "Dear {0}, \nTravel Authorization Form Ref No. {1} has been rejected. \nBelow are the remarks: \n\n{2}";
        public const string ecfRejectedMsgBody = "Dear {0}, \nExpense Claim request request Ref No. {1} has been rejected. \nBelow are the remarks: \n\n{2}";

        #endregion

        #region .Project Manager Notifications.

        public const string orPMNotifyMsgBody = "Dear {0}, \nOrder Request Ref No. {1} has been prepared and sent for approval. \nThank You";
        public const string poPMNotifyMsgBody = "Dear {0}, \nPurchase Order Ref No. {1} has been prepared and sent for financial review. \nThank You";
        public const string rfpPMNotifyMsgBody = "Dear {0}, \nRequest For Payment Ref No. {1} has been prepared and sent for financial review. \nThank You";
        public const string rfaPMNotifyMsgBody = "Dear {0}, \nRequest For Advance Ref No. {1} has been prepared and sent for financial review. \nThank You";        
        public const string spmPMNotifyMsgBody = "Dear {0}, \nSalary Payment request Ref No. {1} has been prepared and sent for financial review. \nThank You";
        public const string tafPMNotifyMsgBody = "Dear {0}, \nTravel Authorization Ref No. {1} has been prepared and sent for financial review. \nThank You";
        public const string ecfPMNotifyMsgBody = "Dear {0}, \nExpense Claim request request Ref No. {1} has been prepared and sent for financial review. \nThank You";

        public const string orPMNotifyApprovedMsgBody = "Dear {0}, \nOrder Request Ref No. {1} has been approved and sent for financial review. \nThank You";
        public const string orPMNotifyReviewedMsgBody = "Dear {0}, \nOrder Request Ref No. {1} has been financially reviewed and sent for authorization. \nThank You";
        public const string poPMNotifyApprovedMsgBody = "Dear {0}, \nPurchase Order Ref No. {1} has been financially reviewed and sent for authorization. \nThank You";
        public const string rfpPMNotifyApprovedMsgBody = "Dear {0}, \nRequest For Payment Ref No. {1} has been financially reviewed and sent for authorization. \nThank You";
        public const string rfaPMNotifyApprovedMsgBody = "Dear {0}, \nRequest For Advance Ref No. {1} has been financially reviewed and sent for authorization. \nThank You";
        public const string spmPMNotifyApprovedMsgBody = "Dear {0}, \nSalary Payment request Ref No. {1} has been financially reviewed and sent for authorization. \nThank You";
        public const string tafPMNotifyApprovedMsgBody = "Dear {0}, \nTravel Authorization Ref No. {1} has been financially reviewed and sent for authorization. \nThank You";
        public const string ecfPMNotifyApprovedMsgBody = "Dear {0}, \nExpense Claim request request Ref No. {1} has been financially reviewed and sent for authorization. \nThank You";

        public const string orPMNotifyAuthorizedMsgBody = "Dear {0}, \nOrder Request Ref No. {1} has been authorized. This action has resulted in commitment of funds in your project budget [{2}]. \nThank You";
        public const string poPMNotifyAuthorizedMsgBody = "Dear {0}, \nPurchase Order Ref No. {1} has been authorized. This action has resulted in commitment of funds in your project budget [{2}]. \nThank You";
        public const string rfpPMNotifyAuthorizedMsgBody = "Dear {0}, \nRequest For Payment Ref No. {1} has been authorized and is ready for posting. This action has resulted in commitment of funds in your project budget [{2}]. \nThank You";
        public const string rfaPMNotifyAuthorizedMsgBody = "Dear {0}, \nRequest For Advance Ref No. {1} has been authorized and is ready for posting. This action has resulted in commitment of funds in your project budget [{2}]. \nThank You";
        public const string spmPMNotifyAuthorizedMsgBody = "Dear {0}, \nSalary Payment request Ref No. {1} has been authorized and is ready for posting. This action has resulted in commitment of funds in your project budget [{2}]. \nThank You";
        public const string tafPMNotifyAuthorizedMsgBody = "Dear {0}, \nTravel Authorization Ref No. {1} has been authorized and is ready for posting. This action has resulted in commitment of funds in your project budget [{2}]. \nThank You";
        public const string ecfPMNotifyAuthorizedMsgBody = "Dear {0}, \nExpense Claim request request Ref No. {1} has been authorized and is ready for posting. This action has resulted in commitment of funds in your project budget [{2}]. \nThank You";

        public const string rfpPMNotifyFundsPostedMsgBody = "Dear {0}, \nRequest For Payment Ref No. {1} has been posted. This action has resulted in posting of funds in your project budget [{2}]. \nThank You";
        public const string rfaPMNotifyFundsPostedMsgBody = "Dear {0}, \nRequest For Advance Ref No. {1} has been posted. This action has resulted in posting of funds in your project budget [{2}]. \nThank You";
        public const string spmPMNotifyFundsPostedMsgBody = "Dear {0}, \nSalary Payment request Ref No. {1} has been posted. This action has resulted in posting of funds in your project budget [{2}]. \nThank You";
        public const string tafPMNotifyFundsPostedMsgBody = "Dear {0}, \nTravel Authorization Ref No. {1} has been posted. This action has resulted in posting of funds in your project budget [{2}]. \nThank You";
        public const string ecfPMNotifyFundsPostedMsgBody = "Dear {0}, \nExpense Claim request request Ref No. {1} has been posted. This action has resulted in posting of funds in your project budget [{2}]. \nThank You";

        #endregion

        #region .Document Preparer Notifications.

        public const string taDocPrepNotifyMsgBody = "Dear {0}, \n Order Request Ref No. {1} has been authorized. You can now go ahead and prepare a Tender Analysis for this OR. \nThank You";
        public const string poDocPrepNotifyMsgBody = "Dear {0}, \n Tender Analysis Ref No. {1} has been evaluated and authorized. You can now go ahead and prepare a Purchase Order from this TA. \nThank You";
        public const string grnDocPrepNotifyMsgBody = "Dear {0}, \n Purchase Order Ref No. {1} has been authorized. You can now go ahead and prepare a Goods Received Note for this PO. \nThank You";
        public const string rfpDocPrepNotifyMsgBody = "Dear {0}, \n Goods Received Note Ref No. {1} has been authorized. You can now go ahead and prepare a Request For Payment. \nThank You";
        
        #endregion

        #region .Notification Subjects.

        public const string orsubject = "Order Request Notification";
        public const string tasubject = "Tender Analysis Notification";
        public const string posubject = "Purchase Order Notification";
        public const string rfpsubject = "Request For Payment Notification";
        public const string rfasubject = "Request For Advance Notification";
        public const string wrnsubject = "Warehouse Release Order Notification";
        public const string spmsubject = "Salary Payment Notification";
        public const string ecfsubject = "Expense Claim Notification";
        public const string grnsubject = "Goods Received Notification";
        public const string wbsubject = "Way Bill Notification";
        public const string tafsubject = "Travel Authorisation Notification";
        public const string ccsubject = "Completion Certificate Notification";
        public const string ppsubject = "Procurement Plan Notification";

        #endregion

        public const string LoginAttemptsExceededUserAccountLocked = "";

        public const string Logistics_Dev_Group = "logistics-dev@googlegroups.com";
        public const string Logistics_Dev_Group_Subject = "SCMS ERROR";
        
        //http://msdn.microsoft.com/en-us/library/ezwyzy7b.aspx

        #region .Lists.

        public static List<DocumentType> GetDocumentTypes()
        {
            List<DocumentType> docTypeList = new List<DocumentType>();
            DocumentType docType;

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.ccCode;
            docType.DocumentName = "Completion Certificate";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.ecfCode;
            docType.DocumentName = "Expense Claim Form";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.grnCode;
            docType.DocumentName = "Goods Received Note";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.orCode;
            docType.DocumentName = "Order Request";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.poCode;
            docType.DocumentName = "Purchase Order";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.rfaCode;
            docType.DocumentName = "Request For Advance";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.rfpCode;
            docType.DocumentName = "Request For Payment";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.spmCode;
            docType.DocumentName = "Salary Payment Form";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.paramsCode;
            docType.DocumentName = "System Parameters";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.tafCode;
            docType.DocumentName = "Travel Authorization Form";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.wrnCode;
            docType.DocumentName = "Warehouse Release Order";
            docTypeList.Add(docType);

            return docTypeList;
        }

        public static List<DocumentType> GetDocumentTypes4Project()
        {
            List<DocumentType> docTypeList = new List<DocumentType>();
            DocumentType docType = new DocumentType();

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.ecfCode;
            docType.DocumentName = "Expense Claim Form";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.orCode;
            docType.DocumentName = "Order Request";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.ppCode;
            docType.DocumentName = "Procurement Plan";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.poCode;
            docType.DocumentName = "Purchase Order";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.rfaCode;
            docType.DocumentName = "Request For Advance";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.rfpCode;
            docType.DocumentName = "Request For Payment";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.spmCode;
            docType.DocumentName = "Salary Payment Form";
            docTypeList.Add(docType);

            docType = new DocumentType();
            docType.DocumentCode = NotificationHelper.tafCode;
            docType.DocumentName = "Travel Authorization Form";
            docTypeList.Add(docType);

            return docTypeList;
        }

        public static List<ActionType> GetActionType(string docType)
        {
            List<ActionType> atList = new List<ActionType>();
            ActionType at = new ActionType();
            switch (docType)
            {
                case orCode:
                    at.Name = approvalCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = authorizationCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = reviewCode;
                    atList.Add(at);
                    break;
                case poCode:
                    at.Name = authorizationCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = reviewCode;
                    atList.Add(at);
                    break;
                case rfpCode:
                    at.Name = authorizationCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = reviewCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = postFundsCode;
                    atList.Add(at);
                    break;
                case rfaCode:
                    at.Name = authorizationCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = reviewCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = postFundsCode;
                    atList.Add(at);
                    break;
                case spmCode:
                    at.Name = authorizationCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = reviewCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = postFundsCode;
                    atList.Add(at);
                    break;
                case ecfCode:
                    at.Name = authorizationCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = reviewCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = postFundsCode;
                    atList.Add(at);
                    break;
                case ppCode:
                    at.Name = approvalCode;
                    atList.Add(at);
                    break;
                case grnCode:
                    at.Name = verificationCode;
                    atList.Add(at);
                    break;
                case wrnCode:
                    at.Name = approvalCode;
                    atList.Add(at);
                    break;
                case ccCode:
                    at.Name = approvalCode;
                    atList.Add(at);
                    break;
                case paramsCode:
                    at.Name = approvalCode;
                    atList.Add(at);
                    break;
                case tafCode:
                    at.Name = authorizationCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = reviewCode;
                    atList.Add(at);

                    at = new ActionType();
                    at.Name = postFundsCode;
                    atList.Add(at);
                    break;
            }
            return atList;
        }

        #endregion

        public static bool ProjectExistsInList(ProjectBLCount pbl, List<ProjectBLCount> pblList)
        {
            foreach (var proj in pblList)
            {
                if (proj.ProjectDonorId.Equals(pbl.ProjectDonorId))
                    return true;
            }
            return false;
        }
    }

    public class DocumentType
    {
        public string DocumentCode { get; set; }

        public string DocumentName { get; set; }
    }

    public class ActionType
    {
        public string Name { get; set; }
    }


}
